package com.hjl.cookie;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ServivE
 * @version 0.1
 * @className CookieController
 * @description
 * @date 2024/8/12 20:20
 * @since jdk11
 */
@Controller
@RequestMapping("cookie")
@ResponseBody
public class CookieController {
    //存cookie
    @GetMapping("save")
    public String save(HttpServletResponse response) {
        Cookie cookie = new Cookie("cookieName", "root");
        response.addCookie(cookie);
        return "ok";
    }

    //取cookie
    @RequestMapping("take")
    public String take(@CookieValue(value = "cookieName") String value) {
        System.out.println("value = " + value);
        return value;
    }
}
